<?php

namespace App\Repository\Sale;

use App\Base\IRI;
use App\Entity\Sale\SaleMiao;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
 * @method SaleMiao|null find($id, $lockMode = null, $lockVersion = null)
 * @method SaleMiao|null findOneBy(array $criteria, array $orderBy = null)
 * @method SaleMiao[]    findAll()
 * @method SaleMiao[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */
class SaleMiaoRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, SaleMiao::class);
    }

    public function get4Choice($isNum = false)
    {
        $data = $this->findBy(array(),array(
            "id"=>"ASC"
        ));
        $choice = [];
        foreach ($data as $row) {
            $choice[] = [
                "id"=>$isNum?
                    $row->getId()
                    :
                    IRI::createIRIStringFromEntity(
                        SaleMiao::class,
                        $row->getId()),
                "value"=>"【{$row->getCircleType()->getName()}】{$row->getTitle()}",
            ];
        }
        return $choice;
    }
}
